/**
 * Created by aa on 2016/7/25.
 */
'use strict';
let Redux=require('redux');
let utils=require('../common/utils.js');
let cr=utils.cr;
let actions=require('../actions/hkfs');

var reducers=Redux.combineReducers({
    //重点产品介绍
    data: cr([], {
        [actions.RECEIVE_PRODUCTITEM_CONTENT](state, action){
            return action.data}
    }),
    //一般产品详情
    homeProductDetailData:cr([],{[actions.RECEIVE_HOME_PRODUCTDETAIL_CONTENT](state,action){
        return action.homeProductDetailData;
    }
    }),
    //财富动态
    homeDynamicDetail:cr([],{[actions.RECEIVE_HOME_DYNAMIC_DETAIL](state,action){
        for(var i=0;i<action.homeDynamicDetail.length;i++){
            var resultItem=action.homeDynamicDetail[i];
            if(resultItem.leftTitle.length>15){
                resultItem.leftTitle=resultItem.leftTitle.substr(0,15)+'...';
            }}
        return action.homeDynamicDetail;
    }
    }),
    //财富新闻
    homeNewDetail:cr([],{[actions.RECEIVE_HOME_NEWS_DETAIL](state,action){
        for(var i=0;i<action.homeNewsDetail.length;i++){
            var resultItem=action.homeNewsDetail[i];
            if(resultItem.title.length>16){
                resultItem.title=resultItem.title.substr(0,16)+'...';
            }
            if(resultItem.content.length>65) {
                resultItem.content = resultItem.content.substr(0, 65) + '...';
            }
        }
        return action.homeNewsDetail;
    }
    }),
    //首页轮播
    homeSliderItems:cr([],{[actions.RECEIVE_HOME_SLIDER_ITEMS](state,action){
        return action.homeSliderItems;
    }
    }),
    homeNotice:cr([],{[actions.RECEIVE_HOME_NOTICE](state,action){
        return action.homeNotice;
    }
    })
});

module.exports=reducers;